﻿var pagecount = "0";
var num = 0;
var page = 1;
var keyword = ""; //关键词
var hannelid = ""; //频道id
var authid = "1"; //作者id
var hid = "";
var itemCount = 0;

$(document).ready(function () {

    if ("wap" == getUrlArgStr("sources")) {
        $(".wamtop").css("display", "none");
    }
    load(page);
    $(window).bind("scroll", function () {
        //当滚动条滚动时
        var scollTop = $(this).scrollTop() + $(this).height();
        var scollH = $(document).height();

        if (scollH - scollTop < 100) {
            // Alert("100");
            if (wait.isShow) { return; } //如果正在加载，则返回  
            page++;
            load(page);

        }
        return false;
    });
});

function load(page) {
    if (pagecount == "1") { return; }
    if (!islogin()) { window.location.href = 'login.html'; return; }
    ajax.GetSharelist("is_other=0&page_index=" + page, function (data) {
        if (data.code != 0) {
            Alert(data.msg);
            pagecount = "1";
            return;
        }
        //if (data.code == "4") { Alert(data.msg.toString()); pagecount = "1"; return; }
        if (data.item.pageCount < page) {
            if (pagecount == "0")
                Alert('到底了！');
            pagecount = "1"; return;
        }

        itemCount = data.item.itemCount;
        $(".topcententxt").html("我的发布 (" + data.item.itemCount + ")");
        $(data.item.table).each(function () {
            num++;
            var logoimg = this.article_logo == null ? "img/30.png" : this.article_logo;
            var titles;
            if (this.type == 1) {
                titles = this.article_title;
            }
            else if (this.type == 2) {
                titles = this.url_title;
                if (this.url_logo != null && this.url_logo != "")
                    logoimg = this.url_logo;
            }

            if (titles == null)
                titles = "";

            if (titles.length > 12)
                titles = titles.substr(0, 12) + "...";

            var url = "detail.aspx?is_app=1&shareid=" + this.id + "&advert_id=" + this.advert_id + "&article_id=" + this.article_id + "&type=" + this.type;
            $(".tg_select").append("<div class=\"centenlist\"><div class=\" centenimg\"><img src=\"" + logoimg + "\"  /></div><div class=\"cententxt\" onclick=\"window.location.href='" + url + "'\" ><div class=\"cententxttop\"><strong>" + titles + "</strong></div><div class=\"centenTime\">" + this.date.substr(0, 10) + "<div class=\"centenflow\" style='width:100px;' name=\"" + this.id + "\" > <div style='width: 50px;float: left;'  ><img src=\"img/flow.jpg\" class=\"imgclick\" name=\"" + this.id + "\" /> " + this.click + "</div> <div><img src=\"img/dianji1.png\"  class=\"imgclick\" name=\"" + this.id + "\" /> " + this.ad_click + "</div></div><div tag=\"" + this.article_id + "\" class=\"check\"><img src=\"img/Delete2.jpg\" class=\"checkimg\"  /><input type=\"hidden\" name=\"checkid\" value=\"" + this.id + "\" /></div></div></div></div>");
        });

        loadhtml();


    });
}

function loadhtml() {
    $(".check").click(function () {
        if (confirm($(this).parent().parent().parent().find('strong').html() + "\n\n  确定删除？")) {
            RemoveShare($(this).children(":last").val(), $(this).attr("tag"), $(this));
         
        }
        return false;
    });

    $(".centenflow").click(function () {
        $(this).css("color", "#F37B0B");
        window.location.href = "Statistical.html?Shareid=" + $(this).attr("name") + "&type=Share";
        return false;
    });

}

function RemoveShare(id,article_id, obj) {
    if (!islogin()) { window.location.href = 'login.html'; return; }
    ajax.RemoveShare("id=" + id + "&article_id=" + article_id, function (data) {
        if (data.msg.toString() == "成功") {
            obj.parent().parent().parent().hide(500);
            //obj.parent().parent().parent().remove();
            $(".topcententxt").html("我的发布 (" + --itemCount + ")");

        }
        else {
            Alert(data.msg.toString());
        }
    });

}

function doSomething(obj, evt, id) {
    var e = (evt) ? evt : window.event; //判断浏览器的类型，在基于ie内核的浏览器中的使用cancelBubble
    if (window.event) {
        e.cancelBubble = true;
    } else {
        //e.preventDefault(); //在基于firefox内核的浏览器中支持做法stopPropagation
        e.stopPropagation();
    }
}

 

 